package com.hzit.user.controller;

import com.hzit.common.util.R;
import com.hzit.common.util.User;
import com.hzit.user.service.IUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/user")
public class UserController {

	@Autowired
	private IUserService userService;
	@Value("${server.port}")
	private int port;
	//1. 查询所有用户
	@GetMapping("list")
	public R list(){
		System.out.println("port:" + port);
		return R.ok(userService.list());
	}

	@GetMapping("/findById")
	public R findById(){
		User user = userService.getById(4);
		return R.ok(user);
	}
	// 微服务调用时，使用@RequestParam("id")参数
	@GetMapping("/findById2")
	public R findById2(@RequestParam(value = "id")  Integer id){
		User user = userService.getById(id);
		return R.ok(user);
	}

	@GetMapping("/findById3/{id}")
	public R findById3(@PathVariable  Integer id){
		User user = userService.getById(id);
		return R.ok(user);
	}
	// 根据用户名查询用户
	@GetMapping("/findUserByUsername")
	public R<User> findUserByUsername(@RequestParam("username") String username){
		User user = userService.findUserByUsername(username);
		return R.ok(user);
	}
	// 根据用户名查询用户的权限串列表
	@GetMapping("/findPermissionsByUsername")
	public R<List<String>> findPermissionsByUsername(@RequestParam("username") String username){
		List<String> permissions = userService.findPermissionsByUsername(username);
		return R.ok(permissions);
	}
}
